//using PK.Broadcaster;
//using PK.InAppPurchase;
//using PKGames.Localization;
//using PKGames.Store.Persistence;
//using System.Collections;
//using UnityEngine;
//using UnityEngine.Purchasing;

//namespace PKGames.Store
//{
//	public sealed class StoreManager : BaseStoreManager
//	{
//		private static StoreManager _instance;

//		[SerializeField]
//		private SpinnerController _spinnerController;

//		private StorePersistenceController _persistenceController;

//		private string _trigger = string.Empty;

//		private string _creativeId = string.Empty;

//		private string _levelName = string.Empty;

//		private const string UnknownStoreId = "unknown";

//		public static StoreManager Instance
//		{
//			get
//			{
//				if (_instance == null)
//				{
//					_instance = (StoreManager)Object.FindObjectOfType(typeof(StoreManager));
//				}
//				return _instance;
//			}
//		}

//		private void Awake()
//		{
//			_instance = this;
//			if (base.gameObject.transform.parent == null)
//			{
//				Object.DontDestroyOnLoad(base.gameObject);
//			}
//			_persistenceController = new StorePersistenceController();
//		}

//		public void PurchaseStoreProduct(StoreProduct storeProduct, string trigger, string creativeId, string levelName)
//		{
//			_trigger = trigger;
//			_creativeId = creativeId;
//			_levelName = levelName;
//			_spinnerController.ShowSpinner();
//			StoreEvents.LogStoreOpen(storeProduct, trigger, creativeId, levelName);
//			PurchaseStoreProduct(storeProduct);
//		}

//		public override void ProcessPurchaseResult(PurchaseResult result, StoreProduct storeProduct, string transactionId)
//		{
//			if (!_persistenceController.IsProductBought(storeProduct) && result == PurchaseResult.Success)
//			{
//				StoreEvents.LogPurchaseSuccess(storeProduct, _trigger, _creativeId, _levelName);
//			}
//			_persistenceController.UpdateProduct(storeProduct, transactionId, result);
//			if (result == PurchaseResult.Success)
//			{
//				MessageBroadcaster.Instance.BroadcastMessage(new ProcessPurchaseSuccessMessage(storeProduct));
//			}
//			_spinnerController.HideSpinner();
//		}

//		protected override void OnTransactionsRestored(bool success)
//		{
//			StoreEvents.LogRestore(success);
//		}

//		public override void OnInitializeFailed(InitializationFailureReason error)
//		{
//		}

//		protected override void OnPurchaseFailed(Product product, PurchaseFailureMessage failureReason)
//		{
//			string productId = (product == null || product.definition == null) ? "unknown" : product.definition.storeSpecificId;
//			MessageBroadcaster.Instance.BroadcastMessage(new PurchaseFailedMessage(productId, failureReason));
//			_spinnerController.HideSpinner();
//		}

//		protected override void OnPurchaseFailed(StoreProduct storeProduct, PurchaseFailureMessage failureReason)
//		{
//			string productId = (!(storeProduct != null)) ? "unknown" : storeProduct.StoreId;
//			MessageBroadcaster.Instance.BroadcastMessage(new PurchaseFailedMessage(productId, failureReason));
//			_spinnerController.HideSpinner();
//		}

//		public bool IsProductBought(StoreProduct storeProduct)
//		{
//			return _persistenceController.IsProductBought(storeProduct);
//		}

//		public IEnumerator WaitForInit()
//		{
//			while (_storeController == null)
//			{
//				yield return new WaitForSeconds(0.1f);
//			}
//		}

//		public string GetCurrencyForProduct(StoreProduct storeProduct)
//		{
//			if (_storeController != null)
//			{
//				Product product = _storeController.products.WithID(storeProduct.StoreId);
//				return MonoSingleton<LocationProvider>.Instance.GetCurrencyString(product.metadata.isoCurrencyCode);
//			}
//			return "$";
//		}

//		public string GetPriceForProduct(StoreProduct storeProduct)
//		{
//			if (_storeController != null)
//			{
//				Product product = _storeController.products.WithID(storeProduct.StoreId);
//				return product.metadata.localizedPrice.ToString("0.00");
//			}
//			return "0.99";
//		}
//	}
//}
